package com.ruoyi.api.knd;

import com.ruoyi.system.domain.JiajiaFaq;
import com.ruoyi.system.service.IJiajiaFaqService;
import com.ruoyi.knd.domain.KndArticle;
import com.ruoyi.knd.service.IKndArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/xieyi")
@Api(tags = "协议管理")
public class ApiKndArticleController {

    @Autowired
    private IKndArticleService articleService;

    @Autowired
    private IJiajiaFaqService faqService;

    @ApiOperation("获取各种协议")
    @GetMapping("/yulan/{id}")
    @ResponseBody
    public String xieYiYuLan(@PathVariable Long id)
    {

        KndArticle knd = articleService.selectKndArticleById(id);
        if (knd == null){
            return getStr("404","404").toString();
        }
        StringBuilder sb = getStr(knd.getTitle(),knd.getContent());
        return sb.toString();
    }


    @ApiOperation("获取各种协议")
    @GetMapping("/wtyulan/{id}")
    @ResponseBody
    public String wenTiYuLan(@PathVariable Long id)
    {
        JiajiaFaq knd = faqService.selectJiajiaFaqById(id);
        if (knd == null){
            return getStr("404","404").toString();
        }
        StringBuilder sb = getStr(knd.getTitle(),knd.getContent());
        return sb.toString();
    }



    private StringBuilder getStr(String title,String content){
        StringBuilder sb = new StringBuilder();
        sb.append("<!doctype html>");

        sb.append("<head>");

        sb.append("<meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0' /> ");

        sb.append("<title>");
        sb.append(title);
        sb.append("</title>");

        sb.append("<style>");

        sb.append(" img {height:auto;width:100%;} ");

        sb.append("</style>");




        sb.append("</head>");



        sb.append("<body>");



        sb.append(content);
        sb.append("</body>");

        sb.append("</html>");

        return sb;
    }
}